function encodeQueryData(url, data)
{
	var ret = [];
	for (var d in data) {
		if (d) {
			ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));
		}
	}
	return url + '?' + ret.join("&");
}

function sqlToJsDate(date) {
	var parts = date.match(/(\d+)/g), i = 0, fmt = {};
	'yyyy-mm-dd'.replace(/(yyyy|dd|mm)/g, function(part) { fmt[part] = i++; });
	return new Date(parts[fmt.yyyy], parts[fmt.mm]-1, parts[fmt.dd]);
}

function formatDateMonthYear(date) {
	var month = '' + (date.getMonth() + 1);
	return (month.length > 1 ? month : '0' + month) + '/' + date.getFullYear();
}

function formatDateDayMonthYear(date) {
	var day = '' + date.getDate();
	return (day.length > 1 ? day : '0' + day) + '/' + formatDateMonthYear(date);
}

function formatAddress(address) {
	return address.address1 + '\n' + address.address2 + '\n' + address.postalCode + ' ' + address.city;
}

function formatMSA(x) {
	return x.brandCode + ' / ' + x.season + ' / ' + x.year;
}

function formatFloat(f) {
	return f.toFixed(2);
}

function formatPrice(price) {
	return formatFloat(price) + ' €';
}

function priceToInt(price) {
	return price.split(' €')[0];
}

function bottom(component) {
	return component.top + component.height;
}

function right(component) {
	return component.left + component.width;
}

function urlImageCustomer(customer) {
	//Ti.API.info('customer : ' + customer);
	var name;
	if (customer == 'Decathlon') {
		name = 'decathlon';
	} else if (customer == 'SKI FUN') {
		name = 'skifun';
	} else if (customer.match(/sport 2000/i)) {
		name = 'sport2000';
	} else if (customer.match(/intersport/i)) {
		name = 'intersport';
	} else {
		name = 'decathlon';
	}
	return 'images/customer/' + name + '.png';
}

function urlImageDiv(div) {
	//Ti.API.info('div : ' + div);
	var name;
	switch (div) {
		case '20':
			name = 'casque';
		break;
		case '21':
			name = 'rollerblade';
		break;
	}
	return 'images/div/' + name + '.png';
}

function urlImageBrand(brand) {
	//Ti.API.info('brand : ' + brand);
	var name;
	switch (brand) {
		case 'VO':
			name = 'voelkl';
		break;
		case '50':
			name = 'rollerblade';
		break;
		case '52':
			name = 'bladerunner';
		break;
	}
	return 'images/brand/' + name + '.png';
}

function urlImageSeason(season) {
	//Ti.API.info('season : ' + season);
	var name;
	switch (season) {
		case 'P':
			name = 'spring';
		break;
		case 'E':
			name = 'summer';
		break;
		case 'A':
			name = 'autumn';
		break;
		case 'H':
			name = 'winter';
		break;
		default:
			name = season;
	}
	return 'images/season/' + name + '.png';
}

function Address(address, city, postalCode) {
	var ad = address.split(';');
	this.address1 = ad[0];
	this.address2 = ad[1];
	this.city = city;
	this.postalCode = postalCode;
}

function equals(obj1, obj2) {
	for (var p in obj1) {
		if (typeof(obj2[p]) == 'undefined') {
			return false;
		}
	}
	
	for (p in obj2) {
		if (typeof(obj1[p]) == 'undefined') {
			return false;
		}
	}

	for (p in obj1) {
		// si p != null
		if (obj1[p]) {
			// si c'est un objet, on appelle récursivement la fonction
			if (typeof(obj1[p]) == 'object') {
				if (!equals(obj1[p], obj2[p])) {
					return false;
				};
			}
			else {
				if (obj1[p] != obj2[p]) {
					return false;
				}
			}
		}
		// obj1[p] == null
		else {
			// obj2[p] doit etre null
			if (obj2[p]) {
				return false;
			}
		}
	}

	return true;
};
